#include "gamekit/Component.h"
#include "gamekit/Scene.h"

using namespace gamekit;

Component::Component(SafePointer<Scene> scene)
	: m_scene(scene),
	m_initialized(false)
{

}

Component::~Component()
{
	m_canvases.clear();
	m_scene->updateCanvasesCache();
}

void Component::init(void)
{
	onInit();

	m_initialized = true;
}

void Component::update(const uint& elapsed)
{
	onUpdate(elapsed);
}

void Component::onInit(void)
{

}

void Component::onUpdate(const uint& elapsed)
{
	GK_UNUSED(elapsed)
}

void Component::add(SharedPointer<Canvas> canvas)
{
	m_canvases.push_back(canvas);
	m_scene->updateCanvasesCache();
}

SafePointer<Scene> Component::scene(void) const
{
	return m_scene;
}

SafePointer<Window> Component::window(void) const
{
	return m_scene->window();
}

std::vector<SharedPointer<Canvas> > Component::canvases(void) const
{
	return m_canvases;
}

bool Component::isInitialized(void) const
{
	return m_initialized;
}
